var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var app1Router = require('./routes/app1');
var app2Router = require('./routes/app2');
var app3Router = require('./routes/app3');
var app4Router = require('./routes/app4');
var app6Router = require('./routes/app6');
var app7Router = require('./routes/app7');
var app8Router = require('./routes/app8');

var app = express();

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(__dirname+'/public',{index:"login.html"}));

app.use('/app1Router', app1Router);
app.use('/app2Router', app2Router);
app.use('/app3Router', app3Router);
app.use('/app4Router', app4Router);
app.use('/app6Router', app6Router);
app.use('/app7Router', app7Router);
app.use('/app8Router', app8Router);

app.use(function(req, res, next) {
  next(createError(404));
});

app.use(function(err, req, res, next) {
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;
